package com.fds.demo.common.bean;

import lombok.Data;

import java.io.Serializable;

/**
 * @author: fds
 * @date: 2020/5/30
 * @description: 统一返回
 */
@Data
public class Result<T> implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * 业务code
	 */
	private Integer businessCode = 1;

	/**
	 * 返回处理消息
	 */
	private String message = "操作成功！";

	/**
	 * 返回代码
	 */
	private Integer code = 1;
	
	/**
	 * 返回数据对象 data
	 */
	private T result;
	
	/**
	 * 时间戳
	 */
	private long timestamp = System.currentTimeMillis();

	public Result() {
	}

	public static<T> Result<T> success(int businessCode, String message, T data) {
		Result<T> r = new Result<>();
		r.setResult(data);
		r.setMessage(message);
		r.setBusinessCode(businessCode);
		return r;
	}

	public static<T> Result<T> success(T data) {
		Result<T> r = new Result<>();
		r.setResult(data);
		return r;
	}

	public static<T> Result<T> error(int code, String message) {
		Result<T> r = new Result<>();
		r.setCode(code);
		r.setMessage(message);
		return r;
	}
}